package com.aspose.cells;

import java.util.ArrayList;
import java.util.Iterator;

public class FormatConditionCollection {
   ConditionalFormattingCollection a;
   private ArrayList f;
   ArrayList b;
   boolean c;
   boolean d = false;
   Worksheet e;

   FormatConditionCollection(ConditionalFormattingCollection cfs) {
      this.a = cfs;
      this.b = new ArrayList(4);
      this.f = new ArrayList(3);
      this.c = false;
      this.e = cfs.b;
   }

   FormatConditionCollection(Worksheet sheet) {
      this.b = new ArrayList(4);
      this.f = new ArrayList(3);
      this.c = false;
      this.e = sheet;
   }

   ArrayList a() {
      return this.f;
   }

   void a(FormatConditionCollection var1) {
      this.c = var1.c;
      this.b = new ArrayList(var1.b.size());
      this.f = new ArrayList(var1.getCount());
      this.d = var1.d;

      for(int var2 = 0; var2 < var1.getCount(); ++var2) {
         FormatCondition var3 = new FormatCondition(this);
         var3.a((FormatCondition)var1.get(var2), (CopyOptions)null);
         com.aspose.cells.b.a.a.ze.a(this.f, (Object)var3);
      }

   }

   void a(FormatConditionCollection var1, CellArea var2, CopyOptions var3) {
      this.c = var1.c;
      this.b = new ArrayList(var1.b.size());
      this.f = new ArrayList(var1.getCount());
      this.d = var1.d;
      com.aspose.cells.b.a.a.ze.a(this.b, (Object)var2);

      for(int var4 = 0; var4 < var1.getCount(); ++var4) {
         FormatCondition var5 = new FormatCondition(this);
         var5.a(var1.get(var4), var3);
         com.aspose.cells.b.a.a.ze.a(this.f, (Object)var5);
      }

   }

   void a(FormatConditionCollection var1, ArrayList var2) {
      this.c = var1.c;
      this.b = new ArrayList(var1.b.size());
      this.f = new ArrayList(var1.getCount());
      this.d = var1.d;
      this.b = var2;

      for(int var3 = 0; var3 < var1.getCount(); ++var3) {
         FormatCondition var4 = new FormatCondition(this);
         var4.a((FormatCondition)var1.get(var3), (CopyOptions)null);
         com.aspose.cells.b.a.a.ze.a(this.f, (Object)var4);
      }

   }

   void b() {
      FormatConditionCollection var1 = new FormatConditionCollection(this.a);
      var1.b = this.b;
      var1.d = this.d;
      var1.c = this.c;

      for(int var2 = 0; var2 < this.getCount(); ++var2) {
         new FormatCondition(var1);
         if (this.get(var2).a(false)) {
            FormatCondition var3 = this.get(var2);
            com.aspose.cells.b.a.a.ze.a(var1.f, (Object)var3);
            this.f.remove(var2);
            --var2;
         }
      }

      this.e.getConditionalFormattings().a(var1);
   }

   boolean a(boolean var1) {
      return this.b(var1) != 0;
   }

   int b(boolean var1) {
      int var2 = 0;
      Iterator var3 = this.f.iterator();

      while(var3.hasNext()) {
         FormatCondition var4 = (FormatCondition)var3.next();
         if (var4.a(var1)) {
            ++var2;
         }
      }

      return var2;
   }

   void a(FormatConditionCollection var1, CopyOptions var2) {
      this.c = var1.c;
      this.b = new ArrayList(var1.b.size());
      this.f = new ArrayList(var1.getCount());
      this.d = var1.d;
      Iterator var3 = var1.b.iterator();

      while(var3.hasNext()) {
         CellArea var4 = (CellArea)var3.next();
         CellArea var5 = new CellArea();
         var5.StartRow = var4.StartRow;
         var5.StartColumn = var4.StartColumn;
         var5.EndRow = var4.EndRow;
         var5.EndColumn = var4.EndColumn;
         com.aspose.cells.b.a.a.ze.a(this.b, (Object)var5);
      }

      for(int var6 = 0; var6 < var1.getCount(); ++var6) {
         FormatCondition var7 = new FormatCondition(this);
         var7.a(var1.get(var6), var2);
         com.aspose.cells.b.a.a.ze.a(this.f, (Object)var7);
      }

   }

   public int[] add(CellArea cellArea, int type, int operatorType, String formula1, String formula2) {
      int[] var6 = new int[]{this.addCondition(type, operatorType, formula1, formula2), com.aspose.cells.b.a.a.ze.a(this.b, (Object)cellArea)};
      return var6;
   }

   public int addArea(CellArea cellArea) {
      int var2 = com.aspose.cells.b.a.a.ze.a(this.b, (Object)cellArea);
      if (var2 == 0) {
         for(int var3 = 0; var3 < this.a().size(); ++var3) {
            ((FormatCondition)this.a().get(var3)).f();
         }
      }

      return var2;
   }

   public int addCondition(int type, int operatorType, String formula1, String formula2) {
      FormatCondition var5 = new FormatCondition(this);
      var5.setType(type);
      var5.setOperator(operatorType);
      var5.setFormula1(formula1);
      var5.setFormula2(formula2);
      com.aspose.cells.b.a.a.ze.a(this.f, (Object)var5);
      var5.setPriority(this.e.e());
      this.e.a(this.e.e() + 1);
      return this.f.size() - 1;
   }

   public int addCondition(int type) {
      FormatCondition var2 = new FormatCondition(this);
      var2.setType(type);
      var2.setPriority(this.e.e());
      this.e.a(this.e.e() + 1);
      return com.aspose.cells.b.a.a.ze.a(this.f, (Object)var2);
   }

   int a(FormatCondition var1) {
      return com.aspose.cells.b.a.a.ze.a(this.f, (Object)var1);
   }

   public int getCount() {
      return this.f.size();
   }

   public int getRangeCount() {
      return this.b.size();
   }

   public FormatCondition get(int index) {
      if (index >= 0 && index < this.getCount()) {
         return (FormatCondition)this.f.get(index);
      } else {
         throw new IllegalArgumentException("Invalid formatting condition index : " + index);
      }
   }

   public CellArea getCellArea(int index) {
      this.a(index);
      return (CellArea)this.b.get(index);
   }

   public void removeArea(int index) {
      this.a(index);
      this.b.remove(index);
   }

   public boolean removeArea(int startRow, int startColumn, int totalRows, int totalColumns) {
      if (this.b != null && this.b.size() != 0) {
         CellArea var5 = new CellArea();
         var5.StartRow = startRow;
         var5.StartColumn = startColumn;
         var5.EndRow = startRow + totalRows - 1;
         var5.EndColumn = startColumn + totalColumns - 1;

         for(int var6 = this.b.size() - 1; var6 >= 0; --var6) {
            CellArea var7 = (CellArea)this.b.get(var6);
            boolean var8 = false;
            boolean[] var9 = new boolean[]{var8};
            CellArea var10 = a(var5, var7, var9);
            var8 = var9[0];
            if (!var8) {
               CellArea var11;
               if (var10.StartRow > var7.StartRow) {
                  var11 = new CellArea();
                  var11.StartRow = var7.StartRow;
                  var11.EndRow = var10.StartRow - 1;
                  var11.StartColumn = var7.StartColumn;
                  var11.EndColumn = var7.EndColumn;
                  com.aspose.cells.b.a.a.ze.a(this.b, (Object)var11);
               }

               if (var10.EndRow < var7.EndRow) {
                  var11 = new CellArea();
                  var11.StartRow = var10.EndRow + 1;
                  var11.EndRow = var7.EndRow;
                  var11.StartColumn = var7.StartColumn;
                  var11.EndColumn = var7.EndColumn;
                  com.aspose.cells.b.a.a.ze.a(this.b, (Object)var11);
               }

               var7.StartRow = var10.StartRow;
               var7.EndRow = var10.EndRow;
               if (var10.StartColumn > var7.StartColumn) {
                  var11 = new CellArea();
                  var11.StartRow = var7.StartRow;
                  var11.EndRow = var7.EndRow;
                  var11.StartColumn = var7.StartColumn;
                  var11.EndColumn = var10.StartColumn - 1;
                  com.aspose.cells.b.a.a.ze.a(this.b, (Object)var11);
               }

               if (var10.EndColumn < var7.EndColumn) {
                  var11 = new CellArea();
                  var11.StartRow = var7.StartRow;
                  var11.EndRow = var7.EndRow;
                  var11.StartColumn = var10.EndColumn + 1;
                  var11.EndColumn = var7.EndColumn;
                  com.aspose.cells.b.a.a.ze.a(this.b, (Object)var11);
               }

               this.b.remove(var6);
            }
         }

         return this.b.size() == 0;
      } else {
         return true;
      }
   }

   static CellArea a(CellArea var0, CellArea var1, boolean[] var2) {
      CellArea var3 = new CellArea();
      var3.StartRow = var0.StartRow < var1.StartRow ? var1.StartRow : var0.StartRow;
      var3.StartColumn = var0.StartColumn < var1.StartColumn ? var1.StartColumn : var0.StartColumn;
      var3.EndRow = var0.EndRow < var1.EndRow ? var0.EndRow : var1.EndRow;
      var3.EndColumn = var0.EndColumn < var1.EndColumn ? var0.EndColumn : var1.EndColumn;
      var2[0] = var3.StartRow > var3.EndRow || var3.StartColumn > var3.EndColumn;
      return var3;
   }

   public void removeCondition(int index) {
      this.f.remove(index);
   }

   boolean c() {
      Iterator var1 = this.f.iterator();

      while(var1.hasNext()) {
         FormatCondition var2 = (FormatCondition)var1.next();
         switch(var2.getType()) {
         case 8:
         case 9:
         case 13:
         case 15:
            return true;
         case 10:
         case 11:
         case 12:
         case 14:
         }
      }

      return false;
   }

   boolean d() {
      Iterator var1 = this.f.iterator();

      while(true) {
         FormatCondition var2;
         byte[] var3;
         do {
            if (!var1.hasNext()) {
               return false;
            }

            var2 = (FormatCondition)var1.next();
            var3 = var2.a();
            if (var3 != null && zyo.a(this.a.b.c(), var3, -1, var3.length - 1)) {
               return true;
            }
         } while(var2.getOperator() != 0 && var2.getOperator() != 7);

         if (var2.c() != null) {
            var3 = var2.c();
            if (var3 != null && zyo.a(this.a.b.c(), var3, -1, var3.length - 1)) {
               return true;
            }
         }
      }
   }

   int[] e() {
      int var1 = 0;
      int var2 = 0;
      if (this.b.size() == 0) {
         return null;
      } else {
         for(int var3 = 0; var3 < this.b.size(); ++var3) {
            CellArea var4 = (CellArea)this.b.get(var3);
            if (var3 == 0) {
               var1 = var4.StartRow;
               var2 = var4.StartColumn;
            } else {
               if (var1 > var4.StartRow) {
                  var1 = var4.StartRow;
               }

               if (var2 > var4.StartColumn) {
                  var2 = var4.StartColumn;
               }
            }
         }

         return new int[]{var1, var2};
      }
   }

   void a(byte[] var1, int var2) {
      this.c = (var1[2] & 255 & 1) != 0;
      short var3 = com.aspose.cells.b.a.zc.b(var1, 12);

      for(int var4 = 14; var4 < var2; var4 += 8) {
         CellArea var5 = new CellArea();
         var5.StartRow = com.aspose.cells.b.a.zc.e(var1, var4) & '\uffff';
         var5.StartColumn = com.aspose.cells.b.a.zc.e(var1, var4 + 4) & '\uffff';
         var5.EndRow = com.aspose.cells.b.a.zc.e(var1, var4 + 2) & '\uffff';
         var5.EndColumn = com.aspose.cells.b.a.zc.e(var1, var4 + 6) & '\uffff';
         com.aspose.cells.b.a.a.ze.a(this.b, (Object)var5);
      }

   }

   void f() {
      Iterator var1 = this.f.iterator();

      while(var1.hasNext()) {
         FormatCondition var2 = (FormatCondition)var1.next();
         var2.f();
      }

   }

   private void a(int var1) {
      if (var1 < 0 || var1 >= this.b.size()) {
         throw new IllegalArgumentException("Invalid conditional formatted cell range index:" + var1);
      }
   }

   void c(boolean var1) {
      int[] var2 = this.e();
      if (var2 != null) {
         int var3 = var2[0];
         int var4 = var2[1];
         Iterator var5 = this.a().iterator();

         while(var5.hasNext()) {
            FormatCondition var6 = (FormatCondition)var5.next();
            if (var6 != null) {
               var6.a(var1, var3, var4);
            }
         }

      }
   }
}
